package cn.daniellee.plugin.rs.component;

import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import java.util.List;

/**
 * 物品生成实用类
 */
public class ItemGenerator {

    public static ItemStack getItem(String name, List<String> lore, String m, int customModelData, int amount) {
        Material material = Material.getMaterial(m.toUpperCase());
        if (material == null) material = Material.STONE;
        ItemStack itemStack = new ItemStack(material);
        itemStack.setAmount(amount);
        ItemMeta itemMeta = itemStack.getItemMeta();
        if (itemMeta != null) {
            itemMeta.setDisplayName(name.replace("&", "§"));
            itemMeta.setCustomModelData(customModelData);
            if (lore != null && !lore.isEmpty()) {
                lore.replaceAll(s -> s.replace("&", "§"));
                itemMeta.setLore(lore);
            }
            itemStack.setItemMeta(itemMeta);
        }
        return itemStack;
    }
}
